package com.nbgs.demo.controller;

import com.nbgs.demo.common.Result;
import com.nbgs.demo.service.AutoGenerateInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;

@CrossOrigin("*")
@RestController
@Slf4j
@Api(tags = "定时生成用水信息", description = "生成用水信息")
public class AutoGenerateConsumptionInfo {
    //定时执行：每个月的25号会生成需要缴费的用户的部分信息

    @Autowired
    private AutoGenerateInfoService autoGenerateInfoService;

    @PostMapping("generateInfo")
    @Scheduled(cron = "0 47 15 21 * ?")
    @ApiOperation("生成信息的方法，不需要参数，指定时间执行")
    private Result generateInfo(){
        log.info("执行了自动生成部分账单的功能");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String time = df.format(System.currentTimeMillis());
        autoGenerateInfoService.generateInfo(time);
        return Result.success();
    }




}
